package com.zmn.plat.services.impl.push;

import java.util.Collections;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.common.utils.number.NumberUtil;
import com.zmn.plat.model.entity.push.notice.PushNoticeAppPutCity;
import com.zmn.plat.persistence.interfaces.push.PushNoticeAppPutCityDao;
import com.zmn.plat.services.interfaces.push.notice.PushNoticeAppPutCityService;

import lombok.extern.slf4j.Slf4j;

/**
 * 描述: app公告推送app关系接口实现类
 *
 * @author wangjie
 * @since 2020/3/24
 **/
@Slf4j
@Service
public class PushNoticeAppPutCityServiceImpl implements PushNoticeAppPutCityService {

    private static final String TAG = "app公告推送app关系接口实现类";

    @Resource
    PushNoticeAppPutCityDao pushNoticeAppPutCityDao;

    /**
     * 描述: 根据主键查询数据
     *
     * @param key
     *            主键id
     * @return com.zmn.plat.model.entity.push.notice.PushNoticePutApp
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    public PushNoticeAppPutCity findByKey(Integer key) {

        if (NumberUtil.isNullOrZero(key)) {
            log.error("[{}],根据主键查询数据失败 key not null or zero,key:{}", TAG, key);
            return null;
        }
        return pushNoticeAppPutCityDao.findByKey(key);
    }

    /**
     * 描述: 根据公告id查询推送app关系数据
     *
     * @param noticeId
     *            公告id
     * @return java.util.List<com.zmn.plat.model.entity.push.notice.PushNoticeAppPutCity>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    public List<PushNoticeAppPutCity> listByNoticeId(Integer noticeId) {

        if (NumberUtil.isNullOrZero(noticeId)) {
            log.error("[{}],根据公告id查询推送app关系数据失败 noticeId not null or zero,key:{}", TAG, noticeId);
            return null;
        }
        return pushNoticeAppPutCityDao.listByNoticeId(noticeId);
    }

    /**
     * 描述: 根据公告id查询推送app关系数据
     *
     * @param noticeIdList
     *            公告id
     * @return java.util.List<com.zmn.plat.model.entity.push.notice.PushNoticePutApp>
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    public List<PushNoticeAppPutCity> listByNoticeIdList(List<Integer> noticeIdList) {

        if (CollectionUtil.isNullOrEmpty(noticeIdList)) {
            log.error("[{}],根据公告id查询推送app关系数据失败, noticeIdList is not null or empty,noticeIdList:{}", TAG, noticeIdList);
            return Collections.emptyList();
        }
        return pushNoticeAppPutCityDao.listByNoticeIdList(noticeIdList);
    }

    /**
     * 描述: 批量新增
     *
     * @param pushNoticeAppPutCityList
     *            app 推送关系数据
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    public void insertBatch(List<PushNoticeAppPutCity> pushNoticeAppPutCityList) {

        if (CollectionUtil.isNullOrEmpty(pushNoticeAppPutCityList)) {
            log.error("[{}],批量新增失败, pushNoticeAppPutCityList is not null or empty,pushNoticeAppPutCityList:{}", TAG, pushNoticeAppPutCityList);
            return;
        }
        pushNoticeAppPutCityDao.insertBatch(pushNoticeAppPutCityList);
    }

    /**
     * 描述: 根据公告id删除推送app关系数据
     *
     * @param noticeId
     *            公告id
     * @author wangjie
     * @since 2020/3/24
     **/
    @Override
    public void deleteByNoticeId(Integer noticeId) {

        if (NumberUtil.isNullOrZero(noticeId)) {
            log.error("[{}],根据公告id查询推送app关系数据失败 noticeId not null or zero,key:{}", TAG, noticeId);
            return;
        }
        pushNoticeAppPutCityDao.deleteByNoticeId(noticeId);
    }
}
